import React, { Component } from 'react'
import Taro from '@tarojs/taro'
import classNames from 'classnames'
import { View, Text } from '@tarojs/components'
import "./index.less"


export default class BuyButton extends Component {
  static defaultProps = {
    text:"买",
    price: 0,
    onClick: ()=>{}
  }
  constructor(props){
    super(props)
    this.state  = {
      stateClass:"up"
    }
  }
  componentWillReceiveProps (nextProps) {
    let stateClass;
    if(nextProps.price > this.props.price){
      stateClass = "up"
    }else{
      stateClass = "down"
    }
    this.setState({stateClass})
  }

  componentWillMount () { }

  componentDidMount () { }

  componentWillUnmount () { }

  componentDidShow () { }

  componentDidHide () { }

  render () {
    const { price, onClick,text } = this.props
    const {stateClass} =this.state
    return (
      <View className={classNames("buy-button",stateClass)} onClick={onClick}>
       <Text className="text">{text}</Text> <Text className="price">{price}</Text>
      </View>
    )
  }
}
